package com.ltkj.baseplatform.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.baseplatform.domain.SerAgreement;
import com.ltkj.baseplatform.service.ISerAgreementService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.page.TableDataInfo;

/**
 * 协议Controller
 * 
 * @author ruoyi
 * @date 2023-09-22
 */
@Api(tags = "协议")
@RestController
@RequestMapping("/agreement")
public class SerAgreementController extends BaseController
{
    @Autowired
    private ISerAgreementService serAgreementService;

    /**
     * 查询协议列表
     */
    @ApiOperation("查询协议列表")
    @RequiresPermissions("baseplatform:agreement:list")
    @GetMapping("/list")
    public TableDataInfo list(SerAgreement serAgreement)
    {
        startPage();
        List<SerAgreement> list = serAgreementService.selectSerAgreementList(serAgreement);
        return getDataTable(list);
    }

    /**
     * 导出协议列表
     */
    @ApiOperation("导出协议列表")
    @RequiresPermissions("baseplatform:agreement:export")
    @Log(title = "协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SerAgreement serAgreement)
    {
        List<SerAgreement> list = serAgreementService.selectSerAgreementList(serAgreement);
        ExcelUtil<SerAgreement> util = new ExcelUtil<SerAgreement>(SerAgreement.class);
        util.exportExcel(response, list, "协议数据");
    }

    /**
     * 获取协议详细信息
     */
    @ApiOperation("获取协议详细信息")
    @RequiresPermissions("baseplatform:agreement:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serAgreementService.selectSerAgreementById(id));
    }

    /**
     * 新增协议
     */
    @ApiOperation("新增协议")
    @RequiresPermissions("baseplatform:agreement:add")
    @Log(title = "协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SerAgreement serAgreement)
    {
        return toAjax(serAgreementService.insertSerAgreement(serAgreement));
    }

    /**
     * 修改协议
     */
    @ApiOperation("修改协议")
    @RequiresPermissions("baseplatform:agreement:edit")
    @Log(title = "协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SerAgreement serAgreement)
    {
        return toAjax(serAgreementService.updateSerAgreement(serAgreement));
    }

    /**
     * 删除协议
     */
    @ApiOperation("删除协议")
    @RequiresPermissions("baseplatform:agreement:remove")
    @Log(title = "协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serAgreementService.deleteSerAgreementByIds(ids));
    }
}
